<?php

/**
 * 举例
 */
require_once('../Curl.php');

//1. 基本演示
function example1() {
	$Curl = new Curl();
	echo $Curl->example();
}

//2. 获取COOKIE
function example2() {
	$Curl = new Curl();
	$data = [
		'url'=>'http://localhost/Server.php',
		//'return_type'=>'string' //返回string类型
		'return_type'=>'array' //返回数组类型
	];
	var_dump($Curl->getCookie($data));
}

//3. 模拟GET请求
function example3() {
	$Curl = new Curl();
	$data = [
		'url'=>'http://localhost/Server.php?id=8',
		'referer'=>'http://www.88.com',
		'cookie'=>'user=admin;pwd=123456',
	];
	echo $Curl->get($data);
}

//4. 模拟POST请求
function example4() {
	$Curl = new Curl();
	$data = [
		'url'=>'http://localhost/Server.php',
		'referer'=>'http://www.88.com',
		'cookie'=>'user=admin;pwd=123456',
		'post_data'=>[
			"user" => "admin",
			"pwd" => "88"
		]
	];
	echo $Curl->post($data);
}

//5. 自定义header
function example5() {
	$Curl = new Curl();
	$data = [
		'url'=>'http://localhost/Server.php',
		'header'=>[
			'Host: m.neihanshequ.com',
			'User-Agent:'.$Curl->agent,
			'CLIENT-IP:'.$Curl->ip,
			'X-FORWARDED-FOR:'.$Curl->ip,
			'Set-Cookie:info=aaaabbbbb',
			'X-Requested-With:'.'XMLHttpRequest',
			'Referer:http://88.com'
		],
		'post_data'=>[
			"user"=>"admin",
			"pwd"=>"88"
		]
	];
	echo $Curl->post($data);
}

//6. 保存远程图片到本地
function example6() {
	$Curl = new Curl();
	$data = [
		'url'=>'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1504367561398&di=751979038529c36dfc7e23ab03e6f46f&imgtype=0&src=http%3A%2F%2Fimage.tianjimedia.com%2FuploadImages%2F2015%2F131%2F41%2F5CI8TD94WZ10.jpg',
		'filename'=>'test' //本地路径 + 图片名，但不要加后缀，会自动加
	];
	var_dump($Curl->saveImg($data));
}

example1();